<template>
  <div :class="'radioGroupComponent '+(cls?cls:'')" v-if="item">
    <span class="title">{{ item.title }}</span>
    <div class="right">
      <div class="box">
        <el-radio-group
          v-model="value"
          @change="elRadiusGroupChange"
          size="small"
        >
          <el-radio-button
            v-for="(b, index) in item.options"
            :key="index"
            :label="b.id"
          >
            <i :class="b.icon"></i>
          </el-radio-button>
          <div class="tips">
            <span v-for="(b, index) in item.options" :key="index">{{
              b.name
            }}</span>
          </div>
        </el-radio-group>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "radioGroupComponent",
  data() {
    return {
      value: null,
      //为了防止页面初始化时，触发不必要的通知更新，此处设置标识符，初始化后2秒置为true
      needUpdate: false,
    };
  },
  created() {},
  props: ["item", "rightIndex", "catalogIndex", "ocIndex", "id","cls"],
  components: {},
  mounted() {
    this.$nextTick(() => {
      this.init();
    });
    setTimeout(() => {
      this.needUpdate = true;
    }, 1000);
  },
  methods: {
    init() {
      if (this.item) {
        this.value = null;
        this.$nextTick(() => {
          let oItem = JSON.parse(JSON.stringify(this.item));
          this.value = oItem.value;
        });
      }
    },
    //点击 选中 其中一个 radiobutton
    elRadiusGroupChange() {
      if (this.needUpdate) {
        let needUpdateMainChild = true;
        // if (this.item.ename === "pageCover") {
        //     needUpdateMain = false;
        // }
        let row = new Object();
        row.value = this.value;
        row.ename = this.item.ename;
        row.rightIndex = this.rightIndex;
        row.catalogIndex = this.catalogIndex;
        row.needUpdateMainChild = needUpdateMainChild;
        row.needUpdateMain = false;
        if (row.ename === "carouselDotsStyle") {
          row.carouselDotsStyleCls = this.item.options[row.value - 1].active;
        }
        if (row.ename === "carouselDotsPosition") {
          row.carouselDotsPositionCls = this.item.options[row.value - 1].active;
        }
        if (row.ename === "titleTextPositionid") {
          let v = "";
          this.item.options.forEach((item) => {
            if (item.id === this.value) {
              v = item.value;
            }
          });
          row.value = this.value + "_" + v;
        }

        this.$emit("updateParent", JSON.stringify(row));
      }
    },
  },
  computed: mapState(["decorate"]),
  watch: {},
};
</script>
<style scoped lang="scss">
.radioGroupComponent {
  display: flex;
  padding: 5px 0px;
  width: 100%;
  box-sizing: border-box;
  .title {
    width: 100px;
    display: flex;
    height: 32px;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    box-sizing: border-box;
    font-size: 12px;
  }
  .right {
    display: flex;
    flex-direction: column;
    width: calc(100% - 100px);
    .box {
      width: auto;
      .tips {
        width: 100%;
        display: flex;
        justify-content: space-around;
        padding-top: 7px;
        font-size: 12px;
        color: #666;
      }
    }
  }
  
}
</style>
<style lang="scss">
.bottomMenuIconStyle{
    .right {
      .box {
        .el-radio-group{width:140px;
          label.el-radio-button{width:70px;}
          .el-radio-button__inner{width:100%;}
          .tips{
            span{width:70px;display: inline-block;text-align: center;}
          }
        }
      }
    }
  }
</style>
